from PIL import Image


def save_img_from_res_arr(img_size, asset_img_path, result_arr, name, format):
    result_size = (len(result_arr[0]),len(result_arr))
    result_img = Image.new("RGB", (result_size[0] * img_size[0], result_size[1] * img_size[1]))
    for row_index in range(len(result_arr)):
        _y = img_size[1] * row_index
        for col_index in range(len(result_arr[0])):
            _x = img_size[0] * col_index
            with open(f'{asset_img_path}/{result_arr[row_index][col_index]}.png', 'rb') as f:
                origin_img = Image.open(f)

                result_img.paste(origin_img, (_x, _y, _x + img_size[0], _y + img_size[1]))

    result_img.save(name, format)
